using System;
using System.Collections.Generic;
using System.Linq;
using WWB.SitePointPrivateMessages.Core.Model.Messages;

namespace WWB.SitePointPrivateMessages.Web.Models
{
    public class MessageSearchViewData
    {
        public MessageSearchViewData(MessageDatabase mdb, IEnumerable<PrivateMessage> selectedMessages) : this(mdb, selectedMessages, new MessageSearchFormOptions())
        {
            
        }

        public MessageSearchViewData(MessageDatabase mdb, IEnumerable<PrivateMessage> selectedMessages, MessageSearchFormOptions opts)
        {
            if (mdb == null) throw new ArgumentNullException("mdb");
            Options = opts ?? new MessageSearchFormOptions();
            SelectedMessages = selectedMessages ?? new PrivateMessage[0];
            UsersList = mdb.Users.Where(x => x.Id >= 0).OrderBy(x => x.Name).AsEnumerable() ?? new ForumUser[0];
            FolderList = mdb.Folders.OrderBy(x => x.Name).AsEnumerable() ?? new Folder[0];
        }

        public IEnumerable<ForumUser> UsersList { get; private set; }
        public IEnumerable<Folder> FolderList { get; private set; }
        public IEnumerable<PrivateMessage> SelectedMessages { get; private set; }
        public MessageSearchFormOptions Options { get; private set; }
    }
}